﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Address.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The address.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Services.Dto
{
    using System;
    using System.Runtime.Serialization;

    /// <summary>
    /// The address.
    /// </summary>
    [DataContract]
    public class Address
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the att.
        /// </summary>
        [DataMember]
        public string Att { get; set; }

        /// <summary>
        /// Gets or sets the city.
        /// </summary>
        [DataMember]
        public string City { get; set; }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        [DataMember]
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets the street name.
        /// </summary>
        [DataMember]
        public string StreetName { get; set; }

        /// <summary>
        /// Gets or sets the street nr.
        /// </summary>
        [DataMember]
        public string StreetNr { get; set; }

        /// <summary>
        /// Gets or sets the zip.
        /// </summary>
        [DataMember]
        public string Zip { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="addr">
        /// The addr.
        /// </param>
        /// <returns>
        /// The <see cref="Address"/>.
        /// </returns>
        public static Address Convert(Models.Domain.Address addr)
        {
            if (addr != null)
            {
                var dto = new Address
                              {
                                  ID = addr.ID, 
                                  StreetName = addr.StreetName, 
                                  Att = addr.Att, 
                                  City = addr.City, 
                                  StreetNr = addr.StreetNr, 
                                  Zip = addr.Zip, 
                              };
                return dto;
            }
            
            return null;
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Queries
{
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Locations;
    using ServiceLibrary.Services.Results;

    /// <summary>
    /// The address query.
    /// </summary>
    [DataContract]
    public class AddressQuery : IQuery
    {
        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <returns>
        /// The <see cref="IResult"/>.
        /// </returns>
        public override IResult Execute(ISession hsession)
        {
            var actioner = new AddressActioner(hsession, null);

            return actioner.ExecuteSearchQuery(this);
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Results
{
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    using ServiceLibrary.Services.Dto;

    /// <summary>
    /// The address result.
    /// </summary>
    [DataContract]
    public class AddressResult : IResult
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="AddressResult"/> class.
        /// </summary>
        public AddressResult()
        {
            this.List = new List<Address>();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the list.
        /// </summary>
        [DataMember]
        public List<Address> List { get; set; }

        /// <summary>
        /// Gets or sets the total row count.
        /// </summary>
        [DataMember]
        public int TotalRowCount { get; set; }

        #endregion
    }
}

namespace ServiceLibrary.Services.Commands
{
    using System;
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Locations;
    using ServiceLibrary.Services.Dto;

    using User = ServiceLibrary.Models.Domain.User;

    /// <summary>
    /// The create address command.
    /// </summary>
    [DataContract]
    public class CreateAddressCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Address Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new AddressActioner(hsession, activeUser);
            actioner.CreateAddress(this);
        }

        #endregion
    }

    /// <summary>
    /// The update address command.
    /// </summary>
    [DataContract]
    public class UpdateAddressCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Address Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new AddressActioner(hsession, activeUser);
            actioner.UpdateAddress(this);
        }

        #endregion
    }

    /// <summary>
    /// The delete address command.
    /// </summary>
    [DataContract]
    public class DeleteAddressCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Guid? Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new AddressActioner(hsession, activeUser);
            actioner.DeleteAddress(this);
        }

        #endregion
    }
}